package com.das.mechanic_base.widget;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.KeyboardView;
import android.os.Build;
import android.os.Handler;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.main.X3LicenseNumberAdapter;
import com.das.mechanic_base.app.X3Constent;
import com.das.mechanic_base.app.X3RouterCenter;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.das.mechanic_base.base.X3IBaseView;
import com.das.mechanic_base.bean.live.LiveSelectCarBean;
import com.das.mechanic_base.bean.main.CarMemberBean;
import com.das.mechanic_base.bean.main.CarModelSelectBean;
import com.das.mechanic_base.bean.main.CarPoolBean;
import com.das.mechanic_base.bean.main.CarPoolMainBean;
import com.das.mechanic_base.bean.main.ValidCarBean;
import com.das.mechanic_base.gen.DaoSessionUtils;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.utils.SpHelper;
import com.das.mechanic_base.utils.SpaceFilter;
import com.das.mechanic_base.utils.X3KeyboardUtil;
import com.das.mechanic_base.utils.X3StringUtils;
import com.das.mechanic_base.utils.X3ToastUtils;
import com.das.mechanic_base.utils.X3Utils;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 创建接车单的逻辑
 * 1、输入车牌号，根据返回的id判断当前车辆的状态如下：
 * status=0 首次到店，
 * status=1 pc端创建了接车单 但是没有完善车辆信息
 * status=2 存在未支付的订单 需要跳转到未支付的订单页面（H5）
 * 搜索车牌的时候调用 ：searchByCarNum 接口如果已经有了车辆信息，那么会在当前页面显示车辆的信息。并且在输入车型的时候将数据带过去。
 * 2、如果是 0和1的状态，点击确认按钮，调用创建接车单的方法：saveReceiveBase。
 * 创建成功之后，跳转到输入车型信息的页面，填写车辆信息。
 * 3、点击下一步到确定信息页面，点击确定的时候，判断当前车辆是否已经上传了 车主头像
 * 一：如果上传了的话，直接调用更新接车单的接口 updateReceiveCar
 * 二：如果没有上传头像，先通过车主的lastName 首字母和随机背景图生成新的图片，并且调用七牛接口：requestQiNiuToken
 * 三：上传七牛成功之后，根据返回的图片地址、七牛id、车辆carId（从updateReceiveCar接口获取车辆id），再调用后台接口：updateCarOwnerUserPortrait进行上传
 */
public class X3BottomHomeWorkDialog extends X3BaseBottomSheetDialog implements View.OnClickListener, TextWatcher, TextView.OnEditorActionListener, X3SelectCarPopuWindow.OnAdapterItemClick, X3LicenseNumberAdapter.ItemOnclick {

    private EditText et_car_num;
    private RelativeLayout rl_load;
    private TextView tv_notice;
    private Button btn_creat;
    private TextView tv_cancel;
    private ImageView iv_check;
    private RelativeLayout rl_header;
    private View v_bg;
    private TextView tv_clear;
    private RelativeLayout rl_content;
    private TextView tv_check;
    private RelativeLayout rl_car;
    private RelativeLayout sl_view;

    private ValidCarBean numBean;
    private PopupWindow keyPop;
    private RecyclerView rlv_number;
    /**
     * 判断下方按钮的状态
     * 0： 需要跳转到另外两个弹框完善车辆与车主信息 才可以创建接车单
     * 1： 正常 直接创建接车单
     * 2： 有未支付订单 需要跳转到未支付订单
     * 3： 车辆不是首次到店，并且已经填写了车辆信息，到下一级页面需要将车辆信息带过去
     */
    private int status = 0;
    private ImageView iv_take;
    private int carId;
    private int carOwnid;
    private X3SelectCarPopuWindow carPopuWindow;
    private long receiveBaseId;
    private String km;
    private Drawable noPayDrawable;
    private String money_code;
    private TextView tv_recent;
    private TextView tv_search;
    private LinearLayout ll_recent;
    private X3LicenseNumberAdapter licenseNumberAdapter;
    private String mobile;
    private CarPoolBean selectCarPoolBean;
    private List<LiveSelectCarBean> dataList;

    public X3BottomHomeWorkDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        tv_clear = getView(R.id.tv_clear);
        iv_take = getView(R.id.iv_take);
        et_car_num = getView(R.id.et_car_num);
        rl_load = getView(R.id.rl_load);
        tv_notice = getView(R.id.tv_notice);
        btn_creat = getView(R.id.btn_creat);
        tv_cancel = getView(R.id.tv_cancel);
        iv_check = getView(R.id.iv_check);
        rl_header = getView(R.id.rl_header);
        v_bg = getView(R.id.v_bg);
        rl_content = getView(R.id.rl_content);
        tv_check = getView(R.id.tv_check);
        rl_car = getView(R.id.rl_car);
        sl_view = getView(R.id.sl_view);
        rlv_number = getView(R.id.rlv_number);
        tv_recent = getView(R.id.tv_recent);
        tv_search = getView(R.id.tv_search);
        ll_recent = getView(R.id.ll_recent);
        tv_search.setOnClickListener(this);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2);
        rlv_number.setLayoutManager(gridLayoutManager);
        licenseNumberAdapter = new X3LicenseNumberAdapter(mContext);
        rlv_number.setAdapter(licenseNumberAdapter);
        licenseNumberAdapter.setOnitemClick(this);
        mobile = (String) SpHelper.getData("mobile", "");
        tv_check.setOnClickListener(this);
        tv_clear.setOnClickListener(this);
        iv_check.setOnClickListener(this);
        iv_take.setOnClickListener(this);
        btn_creat.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);
        rl_car.setOnClickListener(this);
        rl_header.setOnClickListener(this);
        et_car_num.addTextChangedListener(this);
        et_car_num.setOnClickListener(this);

        et_car_num.setFilters(new InputFilter[]{new SpaceFilter()});

        noPayDrawable = ContextCompat.getDrawable(mContext,R.mipmap.x3_car_num_not_paid);
        noPayDrawable.setBounds(0, 0, noPayDrawable.getMinimumWidth(), noPayDrawable.getMinimumHeight());

        et_car_num.setOnEditorActionListener(this);

        if (X3Constent.isChina()) {
            initKeyView();
        }
    }

    public void initData() {
        //数据库查询最近搜索的车牌
        CarMemberBean carMemberBean = DaoSessionUtils.getInstance().searchCarMemberBean( mobile+ "车牌号");

        if(carMemberBean == null){
            tv_recent.setVisibility(View.GONE);
        }else {
            if(X3StringUtils.isListEmpty(carMemberBean.getList())){
                tv_recent.setVisibility(View.GONE);
            }else {
                tv_recent.setText(mContext.getString(R.string.recent_search));
                ll_recent.setVisibility(View.VISIBLE);
                tv_search.setVisibility(View.VISIBLE);
                tv_recent.setVisibility(View.VISIBLE);
                rlv_number.setVisibility(View.VISIBLE);
                licenseNumberAdapter.setData(carMemberBean.getList());
            }
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_home_work_bottom_dialog;
    }


    private X3KeyboardUtil keyboardUtil;

    private void initKeyView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            et_car_num.setShowSoftInputOnFocus(false);
        }
        View view = View.inflate(mContext, R.layout.x3_keyboard_pop, null);
        KeyboardView keyView = view.findViewById(R.id.keyboard_view);
        keyPop = new PopupWindow(view, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        keyPop.setFocusable(true);
        keyPop.setBackgroundDrawable(null);
        keyPop.setOutsideTouchable(true);
        keyboardUtil = new X3KeyboardUtil((Activity) mContext, keyView, et_car_num);
        keyboardUtil.hideSoftInputMethod();
        keyPop.setOnDismissListener(() -> {
            if (keyboardUtil != null) {
                keyboardUtil.hideSoftInputMethod();
                keyboardUtil.hideKeyboard();
            }
        });
    }

    private Handler mHandler = new Handler();

    private Runnable runnable = () -> showWorkInput();

    @Override
    public void show() {
        super.show();
        clearData();
        receiveBaseId = 0;
        if (mHandler != null) {
            mHandler.postDelayed(runnable,200);
        }
        requestCameraList();
    }

    public void showWorkInput() {
        if (X3Constent.isChina()) {
            et_car_num.performClick();
        }else {
            et_car_num.setFocusable(true);
            et_car_num.setFocusableInTouchMode(true);
            et_car_num.requestFocus();
            X3Utils.showInput(et_car_num,mContext);
        }
    }

    private void clearData() {
        et_car_num.setText("");
        rl_content.setVisibility(View.GONE);
        btn_creat.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_point_bg));
        btn_creat.setEnabled(false);
        tv_clear.setVisibility(View.GONE);

    }

    /**
     * 请求摄像头捕获的车牌号
     */
    private void requestCameraList() {
        Log.e("SSSS","请求摄像头捕获");
        NetWorkHttp.getApi().listTyreDetectionCarNum()
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(((X3IBaseView)mContext).bindToLife())
                .subscribe(new HttpCallBack<List<LiveSelectCarBean>>() {
                    @Override
                    protected void onDone(List<LiveSelectCarBean> mList) {
                        if (X3StringUtils.isListEmpty(mList)) {
                            initData();
                            return;
                        }
                        tv_recent.setText(mContext.getString(R.string.x3_camera_car_num));
                        dataList = mList;
                        //刷新数据
                        if(licenseNumberAdapter == null){
                            return;
                        }
                        ll_recent.setVisibility(View.VISIBLE);
                        licenseNumberAdapter.setData(dataList);
                        rlv_number.setVisibility(View.VISIBLE);
                        tv_recent.setVisibility(View.VISIBLE);
                        tv_search.setVisibility(View.GONE);

                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tv_check) {/**
         * TODO 跳转到接车单详情
         */
            //TODO 存在未支付的订单 需要跳转到未支付的订单页面
            if (!X3Utils.isFastClick()) {
                return;
            }
            X3RouterCenter.startReceiveOrder(receiveBaseId,0,false,false);

            dismiss();
        } else if (id == R.id.iv_take) {// 调用拍照
            clearData();
            if (iOnClick != null) {
                iOnClick.iOnClikCamera();
            }
        } else if (id == R.id.btn_creat) {
            if (!X3Utils.isFastClick()) {
                return;
            }
            if (iOnClick != null) {
                if (numBean == null) {
                    numBean = new ValidCarBean();
                }
                if (selectCarPoolBean == null) {//null代表手动输入的  不为null则是点击获取的
                    selectCarPoolBean = new CarPoolBean();
                    selectCarPoolBean.label = et_car_num.getText().toString();
                    selectCarPoolBean.kwParam = new CarPoolBean.KwParamBean();
                    selectCarPoolBean.kwParam.carBrandImgUrl = "";
                    if (!X3StringUtils.isListEmpty(dataList)) {
                        for (int i = 0; i < dataList.size(); i++) {
                            if (selectCarPoolBean.label.equals(dataList.get(i).num.replaceAll("<em>", "").replaceAll("</em>", ""))) {
                                selectCarPoolBean.kwParam.carBrandImgUrl = dataList.get(i).carBrandImgUrl;
                            }
                        }
                    }
                }
//                   iOnClick.iOnClickBtn(status, et_car_num.getText().toString(), receiveBaseId);
                //车牌号存储到数据库
                CarMemberBean carMemberBean = DaoSessionUtils.getInstance().searchCarMemberBean(mobile + "车牌号");
                if (carMemberBean == null) {
                    carMemberBean = new CarMemberBean();
                    List<LiveSelectCarBean> list = new ArrayList<>();
                    LiveSelectCarBean liveSelectCarBean = new LiveSelectCarBean();
                    liveSelectCarBean.carBrandImgUrl = selectCarPoolBean.kwParam.carBrandImgUrl;
                    liveSelectCarBean.num = selectCarPoolBean.label;
                    list.add(liveSelectCarBean);
                    carMemberBean.setList(list);
                    carMemberBean.setCarName(mobile + "车牌号");
                    DaoSessionUtils.getInstance().insertCarMemberBean(carMemberBean);
                } else {
                    List<LiveSelectCarBean> list = carMemberBean.getList();
                    if (X3StringUtils.isListEmpty(list)) {
                        list = new ArrayList<>();
                    }
                    boolean isEqual = false;
                    for (LiveSelectCarBean liveSelectCarBean : list) {
                        if (!liveSelectCarBean.num.equals(selectCarPoolBean.label)) {
                            continue;
                        }
                        isEqual = true;
                        break;
                    }
                    if (!isEqual) {
                        if (list.size() >= 6) {
                            Collections.reverse(list);
                            list.remove(0);
                            LiveSelectCarBean liveSelectCarBean = new LiveSelectCarBean();
                            liveSelectCarBean.carBrandImgUrl = selectCarPoolBean.kwParam.carBrandImgUrl;
                            liveSelectCarBean.num = selectCarPoolBean.label;
                            carMemberBean.setCarName(mobile + "车牌号");
                            list.add(liveSelectCarBean);
                            Collections.reverse(list);
                            carMemberBean.setList(list);
                            DaoSessionUtils.getInstance().updateCarMemberBean(carMemberBean);
                        } else {
                            LiveSelectCarBean liveSelectCarBean = new LiveSelectCarBean();
                            liveSelectCarBean.carBrandImgUrl = selectCarPoolBean.kwParam.carBrandImgUrl;
                            liveSelectCarBean.num = selectCarPoolBean.label;
                            carMemberBean.setCarName(mobile + "车牌号");
                            Collections.reverse(list);
                            list.add(liveSelectCarBean);
                            Collections.reverse(list);
                            carMemberBean.setList(list);
                            DaoSessionUtils.getInstance().insertCarMemberBean(carMemberBean);
                        }
                    } else {//车牌号相同时 更新图标
                        if (!X3StringUtils.isListEmpty(dataList)) {
                            for (int i = 0; i < list.size(); i++) {
                                if (X3StringUtils.isEmpty(list.get(i).carBrandImgUrl)) {
                                    list.get(i).carBrandImgUrl = selectCarPoolBean.kwParam.carBrandImgUrl;
                                    carMemberBean.setList(list);
                                    carMemberBean.setCarName(mobile + "车牌号");
                                    DaoSessionUtils.getInstance().updateCarMemberBean(carMemberBean);
                                }
                            }
                        }

                    }
                }
                if (iOnClick != null) {
                    iOnClick.iOnSearchNum(et_car_num.getText().toString());
                }
            }
        } else if (id == R.id.tv_cancel) {
            dismiss();
        } else if (id == R.id.rl_header) {
            if (iOnClick != null) {
                iOnClick.iOnClickHeader(carOwnid);
            }
        } else if (id == R.id.rl_car) {
            if (iOnClick != null) {
                iOnClick.iOnClickCar(carId);
            }
        } else if (id == R.id.tv_clear) {/**
         * 清空
         */
            clearData();
        } else if (id == R.id.iv_check) {
            if (carPopuWindow != null) {
                carPopuWindow.showPopu(iv_check);
                v_bg.setVisibility(View.VISIBLE);
            }
        } else if (id == R.id.et_car_num) {
            if (X3Constent.isChina()) {
                if (!keyPop.isShowing()) {
                    String s = et_car_num.getText().toString();
                    if (!X3StringUtils.isEmpty(s) && s.length() >= 1) {
                        // 已经输入了省代码
                        keyboardUtil.changeKeyboard(true);
                    } else {
                        keyboardUtil.changeKeyboard(false);
                    }
                    keyPop.showAtLocation(sl_view, Gravity.BOTTOM, 0, 0);
                    keyboardUtil.showKeyboard();
                } else {
                    keyPop.dismiss();
                }
            }
        } else if (id == R.id.tv_search) {
            X3CarPoolDailog carPoolDailog = new X3CarPoolDailog(mContext);
            carPoolDailog.show();
            carPoolDailog.setOnItemClick(carPoolBean -> {
                carPoolDailog.dismiss();
                selectCarPoolBean = carPoolBean;
                et_car_num.setText(carPoolBean.label);
                et_car_num.setSelection(carPoolBean.label.length());
                btn_creat.performClick();

            });
            //车辆池
            NetWorkHttp.getApi().listStoreAllCarNum()
                    .compose(((X3IBaseView) mContext).bindToLife())
                    .compose(RxSchedulersHelper.defaultComposeRequest())
                    .subscribe(new HttpCallBack<CarPoolMainBean>() {
                        @Override
                        protected void onDone(CarPoolMainBean carPoolMainBean) {
                            if (carPoolMainBean == null) {
                                X3ToastUtils.showMessage(mContext.getString(R.string.x3_home_no_select));
                                List<CarModelSelectBean> selectLists = new ArrayList<>();
                                carPoolDailog.changeData(mContext.getString(R.string.car_pool), new ArrayList<>(), selectLists);
                                return;
                            }
                            if (X3StringUtils.isListEmpty(carPoolMainBean.list)) {
                                X3ToastUtils.showMessage(mContext.getString(R.string.x3_home_no_select));
                                List<CarModelSelectBean> selectLists = new ArrayList<>();
                                carPoolDailog.changeData(mContext.getString(R.string.car_pool), carPoolMainBean.list, selectLists);
                                return;
                            } else {
                                if (carPoolDailog != null) {
                                    List<CarModelSelectBean> selectLists = new ArrayList<>();
                                    carPoolDailog.changeData(mContext.getString(R.string.car_pool), carPoolMainBean.list, selectLists);
                                }
                            }
                        }

                        @Override
                        protected String LoadingMessage() {
                            return null;
                        }

                        @Override
                        protected void showError(String error) {

                        }
                    });
        }
    }

    IOnClick iOnClick;

    public void setiOnClick(IOnClick iOnClick) {
        this.iOnClick = iOnClick;
    }

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        if (charSequence == null) {
            return;
        }
        if (charSequence.toString().contains(" ")) {
            String[] str = charSequence.toString().split(" ");
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < str.length; j++) {
                sb.append(str[j]);
            }
            if (!X3StringUtils.isEmpty(sb.toString())) {
                et_car_num.setText(sb.toString());
                et_car_num.setSelection(sb.length());
            }
        }
    }

    @Override
    public void afterTextChanged(Editable editable) {
        if (editable == null) {
            return;
        }
        //去除空格
        String carNum = editable.toString().replaceAll(" ", "");

        if (X3StringUtils.isEmpty(carNum)) {
            rl_content.setVisibility(View.GONE);
            btn_creat.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_point_bg));
            btn_creat.setEnabled(false);
            tv_clear.setVisibility(View.GONE);
            return;
        }
        tv_clear.setVisibility(View.VISIBLE);
        tv_notice.setText("");
        btn_creat.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_dialog_affirm));
        btn_creat.setEnabled(true);

        //转大写
        String newCarNum = carNum.toUpperCase();
        Matcher matcher = pattern.matcher(carNum);
        if (matcher.matches()) {
            et_car_num.setText(newCarNum);
            et_car_num.setSelection(newCarNum.length());
        }

//        // 搜索车牌号
//        if (iOnClick != null) {
//            iOnClick.iOnSearchNum(newCarNum);
//        }
        if(selectCarPoolBean != null){
            return;
        }
        if(carNum.length() >= 2){
            if(X3StringUtils.isEmpty(carNum)){
                searchCarMember(new HashMap<>());
            }else {
                HashMap<String,Object> map = new HashMap<>();
                map.put("keyword",carNum);
                searchCarMember(map);
            }
        }else {
            requestCameraList();
        }

    }

    private Pattern pattern = Pattern.compile(".*[a-z]+.*");

    @Override
    public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
        if (i == EditorInfo.IME_ACTION_SEARCH) {
            String carNum = et_car_num.getText().toString();
//            if (iOnClick != null) {
//                iOnClick.iOnSearchNum(carNum);
//            }
        }
        return true;
    }

    @Override
    public void onAdapterClick(String carNum) {
        if (!X3StringUtils.isEmpty(carNum)) {
            et_car_num.setText(carNum);
            et_car_num.setSelection(carNum.length());
        }
//        if (iOnClick != null) {
//            iOnClick.iOnSearchNum(carNum);
//        }
    }

    public void setReceiveId(int receiveId) {
        this.receiveBaseId = receiveId;
    }

    @Override
    public void onItemClick(String carNum,String imgUrl) {//搜索点击
        selectCarPoolBean = new CarPoolBean();
        selectCarPoolBean.label = carNum;
        selectCarPoolBean.kwParam = new CarPoolBean.KwParamBean();
        selectCarPoolBean.kwParam.carBrandImgUrl = imgUrl;
        et_car_num.setText(carNum);
        et_car_num.setSelection(carNum.length());
        btn_creat.performClick();
    }

    public interface IOnClick {
        void iOnClikCamera();

        void iOnClickBtn(int status, String carNum, long receivedId);

        void iOnSearchNum(String carNum);

        // 跳转到车主详情
        void iOnClickHeader(long carOwnId);

        // 跳转到车辆详情
        void iOnClickCar(long carId);
    }

    public void setCarNum(String carNum) {
        et_car_num.setText(carNum);
        et_car_num.setSelection(carNum.length());
        rl_load.setVisibility(View.VISIBLE);
    }

    @SuppressLint("StringFormatInvalid")
    public void setCarInfo(ValidCarBean numBean) {
        //接口成功后
        selectCarPoolBean = null;//避免第二次存数据存不进去
        rl_load.setVisibility(View.GONE);
        if(numBean == null){
            return;
        }
        this.carId = carId;
        boolean exist = numBean.isExist();
        if (!exist) {
            receiveBaseId = numBean.getReceiveBaseId();
            status = (receiveBaseId == 0) ? 0 : 1;
            if (receiveBaseId != 0 && X3Utils.isFastClick()) {
                X3RouterCenter.startReceiveOrder(receiveBaseId,carId,false,false);
                dismiss();
                return;
            }
            iOnClick.iOnClickBtn(status, et_car_num.getText().toString(), receiveBaseId);
        } else {

            receiveBaseId = numBean.getReceiveBaseId();
            status = (receiveBaseId != 0) ? 2 : 0;
            if (receiveBaseId != 0 && X3Utils.isFastClick()) {
                X3RouterCenter.startReceiveOrder(receiveBaseId,carId,false,false);
                dismiss();
                return;
            }
            X3PickUpListDialog pickUpListDialog = new X3PickUpListDialog(mContext);
            pickUpListDialog.show();
            pickUpListDialog.changeData(numBean,et_car_num.getText().toString().trim());
            pickUpListDialog.setIonClickCreate(new X3PickUpListDialog.IonClickCreate() {
                @Override
                public void ionclickcheck(long receiveBaseId) {
                    if (!X3Utils.isFastClick()) {
                        return;
                    }
                    X3RouterCenter.startReceiveOrder(receiveBaseId,0,false,false);
                }

                @Override
                public void ionClickCreate(int status, String carNum, long receiveBaseId) {
                    iOnClick.iOnClickBtn(status, et_car_num.getText().toString(), receiveBaseId);
                }

                @Override
                public void iOnClickHeader(long carOwnid) {
                    if (iOnClick != null) {
                        iOnClick.iOnClickHeader(carOwnid);
                    }
                }

                @Override
                public void iOnClickCar(long carId) {
                    if (iOnClick != null) {
                        iOnClick.iOnClickCar(carId);
                    }
                }
            });
        }
    }

    @Override
    public void dismiss() {
        receiveBaseId = 0;
        if (keyPop != null && keyPop.isShowing()) {
            keyPop.dismiss();
        }
        if (mHandler != null) {
            mHandler.removeCallbacks(runnable);
        }
        super.dismiss();
    }

    @Override
    protected void onStart() {
        super.onStart();
        MobclickAgent.onPageStart("接车单车牌号弹窗");
    }

    @Override
    protected void onStop() {
        super.onStop();
        MobclickAgent.onPageEnd("接车单车牌号弹窗");
    }

    /**
     * 搜索车牌号接口
     */
    private void searchCarMember(HashMap<String,Object> map){
        NetWorkHttp.getApi().listStoreCarNumReceive(map)
                .compose(((X3IBaseView)mContext).bindToLife())
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .subscribe(new HttpCallBack<List<LiveSelectCarBean>>() {
                    @Override
                    protected void onDone(List<LiveSelectCarBean> datalist) {
                        if(X3StringUtils.isListEmpty(datalist)){
                            return;
                        }
                        dataList = datalist;
                        //刷新数据
                        if(licenseNumberAdapter == null){
                            return;
                        }
                        ll_recent.setVisibility(View.VISIBLE);
                        licenseNumberAdapter.setData(datalist);
                        rlv_number.setVisibility(View.VISIBLE);
                        tv_recent.setVisibility(View.GONE);
                        tv_search.setVisibility(View.VISIBLE);

                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

}
